package com.sharding.issuse.Service.impl;

import com.sharding.issuse.Service.TestService;
import com.sharding.issuse.dao.AutoRruleFlowMapper;
import com.sharding.issuse.dao.RobotCaseMapper;
import com.sharding.issuse.dao.RobotContactMapper;
import com.sharding.issuse.model.AutoRruleFlow;
import com.sharding.issuse.model.RobotContact;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @author Alan
 * @date 2018-05-21
 */
@Service
public class TestServiceImpl implements TestService {
    @Autowired
    private RobotContactMapper robotContactMapper;
    @Autowired
    private RobotCaseMapper robotCaseMapper;
    @Autowired
    private AutoRruleFlowMapper autoRruleFlowMapper;

    @Transactional
    @Override
    public void testSpringTransaction() {
        //条件查询A 表robotContact_5
        RobotContact contactEntity1 = robotContactMapper.selectContactInfoByCon(5165L, 86196476572602368L);

        try {
            //条件查询B 表robotContact_6
            RobotContact contactEntity2 = robotContactMapper.selectContactInfoByCon(5166L, 86196477994471424L);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            //条件查询c 表robotContact_5
            RobotContact contactEntity3 = robotContactMapper.selectContactInfoByCon(5153L, 86196476572602367L);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            //条件查询A 表robotContact_5
            RobotContact contactEntity4 = robotContactMapper.selectContactInfoByCon(5165L, 86196476572602368L);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Transactional
    @Override
    public void tetsRollBack() {
        AutoRruleFlow build = AutoRruleFlow.builder()
                .bguid("test")
                .bgid(1)
                .bguid("test")
                .allBusiness(true)
                .bids("tets")
                .createTime(new Date())
                .name("test")
                .build();

        autoRruleFlowMapper.insert(build);
        build.setBgid(2);
        autoRruleFlowMapper.insert(build);
        throw new RuntimeException();

    }

    @Override
    public void tetsNoRollBack() {
        AutoRruleFlow build = AutoRruleFlow.builder()
                .bguid("test")
                .bgid(1)
                .bguid("test")
                .allBusiness(true)
                .bids("tets")
                .createTime(new Date())
                .name("test")
                .build();

        autoRruleFlowMapper.insert(build);
        build.setBgid(2);
        autoRruleFlowMapper.insert(build);

    }

}
